import request from '@/utils/request'

// 用户相关接口
export const userApi = {
  login: (data) => {
    return request({
      url: '/api/Auth/Login',
      method: 'post',
      data
    })
  },
  getUserInfo: () => {
    return request({
      url: '/api/User/Info',
      method: 'get'
    })
  },
  getUserList: (params) => {
    return request({
      url: '/api/User',
      method: 'get',
      params
    })
  },
  createUser: (data) => {
    return request({
      url: '/api/User/Create',
      method: 'post',
      data
    })
  },
  updateUser: (id, data) => {
    return request({
      url: `/api/User/Update/${id}`,
      method: 'put',
      data
    })
  },
  deleteUser: (id) => {
    return request({
      url: `/api/User/Delete/${id}`,
      method: 'delete'
    })
  },
  changePassword: (data) => {
    return request({
      url: '/api/User/ChangePassword',
      method: 'post',
      data
    })
  }
}

// 角色相关接口
export const roleApi = {
  getRoleList: (params) => {
    return request({
      url: '/api/Role/List',
      method: 'get',
      params
    })
  },
  createRole: (data) => {
    return request({
      url: '/api/Role/Create',
      method: 'post',
      data
    })
  },
  updateRole: (id, data) => {
    return request({
      url: `/api/Role/Update/${id}`,
      method: 'put',
      data
    })
  },
  deleteRole: (id) => {
    return request({
      url: `/api/Role/Delete/${id}`,
      method: 'delete'
    })
  },
  assignPermissions: (roleId, data) => {
    return request({
      url: `/api/Role/AssignPermissions/${roleId}`,
      method: 'post',
      data
    })
  }
}

// 权限相关接口
export const permissionApi = {
  getPermissionList: () => {
    return request({
      url: '/api/Permission/List',
      method: 'get'
    })
  },
  getPermissionTree: () => {
    return request({
      url: '/api/Permission/Tree',
      method: 'get'
    })
  },
  createPermission: (data) => {
    return request({
      url: '/api/Permission/Create',
      method: 'post',
      data
    })
  },
  updatePermission: (id, data) => {
    return request({
      url: `/api/Permission/Update/${id}`,
      method: 'put',
      data
    })
  },
  deletePermission: (id) => {
    return request({
      url: `/api/Permission/Delete/${id}`,
      method: 'delete'
    })
  }
}

// 部门相关接口
export const departmentApi = {
  getDepartmentList: () => {
    return request({
      url: '/api/Department/List',
      method: 'get'
    })
  },
  getDepartmentTree: () => {
    return request({
      url: '/api/Department/Tree',
      method: 'get'
    })
  },
  createDepartment: (data) => {
    return request({
      url: '/api/Department/Create',
      method: 'post',
      data
    })
  },
  updateDepartment: (id, data) => {
    return request({
      url: `/api/Department/Update/${id}`,
      method: 'put',
      data
    })
  },
  deleteDepartment: (id) => {
    return request({
      url: `/api/Department/Delete/${id}`,
      method: 'delete'
    })
  }
}
